package com.zzyl.nursing.controller;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.Device;
import com.zzyl.nursing.dto.DeviceDto;
import com.zzyl.nursing.service.IDeviceService;
import com.zzyl.nursing.vo.DeviceDetailVo;
import com.zzyl.nursing.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设备Controller
 * 
 * @author ruoyi
 * @date 2025-04-28
 */
@RestController
@RequestMapping("/nursing/device")
@Api(tags = "设备的接口")
public class DeviceController extends BaseController
{
    @Autowired
    private IDeviceService deviceService;

    @GetMapping("/queryProduct/{productKey}")
    public AjaxResult queryProduct(@PathVariable String productKey){
        return deviceService.queryProduct(productKey);
    }

    @DeleteMapping("/{iotId}")
    public AjaxResult delDevice(@PathVariable String iotId){
        return toAjax(deviceService.deleteDeviceById(iotId));
    }

    @PutMapping
    public AjaxResult updateDevice(@RequestBody DeviceDto dto){
        return toAjax(deviceService.updateDevice(dto));
    }

    @GetMapping("/queryServiceProperties/{iotId}")
    public AjaxResult queryServiceProperties(@PathVariable String iotId){
        return deviceService.queryServiceProperties(iotId);
    }

    @GetMapping("/{iotId}")
    public AjaxResult getInfo(@PathVariable String iotId){
        DeviceDetailVo vo = deviceService.getInfo(iotId);
        return success(vo);
    }

    @PostMapping("/register")
    public AjaxResult registerDevice(@RequestBody DeviceDto dto){
        deviceService.registerDevice(dto);
        return success();
    }


    @GetMapping("/allProduct")
    public AjaxResult allProduct(){
        List<ProductVo> list = deviceService.allProduct();
        return success(list);
    }

    @PostMapping("/syncProductList")
    public AjaxResult syncProductList(){
        deviceService.syncProductList();
       return success();
    }

    /**
     * 查询设备列表
     */
    @ApiOperation("查询设备列表")
    @PreAuthorize("@ss.hasPermi('nursing:device:list')")
    @GetMapping("/list")
    public TableDataInfo list(Device device)
    {
        startPage();
        List<Device> list = deviceService.selectDeviceList(device);
        return getDataTable(list);
    }
}
